package core.database;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Type;

@Entity(name = "core.Election")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(name = "elections")
public class Election<EV extends ElectionVoter<?, ?>> implements Serializable {
	private static final long serialVersionUID = 9106642778327932592L;
	
	@Id
	@Column(name = "id")
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id = null;
	@Column(name = "name")
	// , nullable = false
	private String name;
	@Column(name = "description")
	@Type(type = "text")
	private String description;
	@Column(name = "startDate")
	// , nullable = false
	@Type(type = "timestamp")
	private Date startDate;
	@Column(name = "endDate")
	// , nullable = false
	@Type(type = "timestamp")
	private Date endDate;
	@Column(name = "status")
	// , nullable = false
	private ElectionStatus status;
	@Column(name = "cards")
	@Type(type = "text")
	private String cards;
	
	@OneToMany
	@JoinColumn(name = "election")
	private Set<EV> voters = new HashSet<EV>();
	
	public Long getId() {
		return id;
	}

	@SuppressWarnings("unused")
	private void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public ElectionStatus getStatus() {
		return status;
	}

	public void setStatus(ElectionStatus status) {
		this.status = status;
	}

	public String getCards() {
		return cards;
	}

	public void setCards(String cards) {
		this.cards = cards;
	}
	
	public Set<EV> getVoters() {
		return voters;
	}

	public void setVoters(Set<EV> voters) {
		this.voters = voters;
	}
}
